
export default {
  indexOf(array, selector, executionContext) {
    if (array) {
        for ( var ctr = 0, len = array.length; ctr < len; ctr++) {
            if (executionContext ? selector.call(executionContext, array[ctr]) : selector(array[ctr])) {
                return ctr;
            }
        }
    }
    return null;
  },

  findIndex(array, attribute, value) {
    return this.indexOf(array, function(object) {
        if (object) {
            var compareWith = attribute ? object[attribute] : object;
            if (typeof compareWith == 'function' && typeof value != 'function') {
                compareWith = compareWith.apply(object);
            }
            return compareWith == value;
        }
        return false;
    });
  },

  findObject(array, attribute, value) {
    var index = this.findIndex(array, attribute, value);
    return index != null ? array[index] : null;
  },
  escapeHTML(text,nl,empty) {
    if (typeof nl != 'string') nl = "\n";
    if (typeof empty != 'string') empty = "";

    return ((text||"").toString().
      replace(/&/g,'&amp;').
      replace(/</g,'&lt;').
      replace(/>/g,'&gt;').
      replace(/\"/g,'&quot;').
      replace(/\'/g,'&#39;').
      replace(/\n|\r\n?/g, nl)) || empty;
  },
  
}



